/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qual2009;

import java.util.Date;
import java.io.IOException;
import static chanlib.Chan_IO.*;

/**
 * @author robit
 */
public class WelcomeToCodeJam{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C

    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }

    /*
      calculate the answer
    */
    private static void reckon(int line) {
        String text=Line();
        int tn=text.length();
        String str="welcome to code jam";
        int sn=str.length();
        int sub[][]=new int[sn+1][tn+1];
        sub[0][0]=1;
        for(int lent=1;lent<=tn;lent++){
            sub[0][lent]=1;
            for(int lens=1;lens<=sn;lens++){
                if(text.charAt(lent-1)==str.charAt(lens-1)){
                    sub[lens][lent]=sub[lens][lent-1]%10000+sub[lens-1][lent-1]%10000;
                }else sub[lens][lent]=sub[lens][lent-1]%10000;
            }
        }
        
         
        int temp=sub[sn][tn]%10000,d=0;
        while(temp>0){temp/=10;d++;}
        String ans=sub[sn][tn]%10000==0?"":sub[sn][tn]%10000+"";

        while(d<4){ans="0"+ans;d++;}

        String output=String.format("Case #%d: %s",line,ans);
        writeln(output, OUTFILE);
        //writeln(String.format("N=%d K=%d\n%s", N, K, ans),ANALFILE);
        //println(output);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="C";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            initIO(filename);
            int lineNums = Integer.parseInt(Line());

            for (int i = 1; i <= lineNums; i++) {
                reckon(i);
            }
        } finally {
            endIO();
        }
    }

}
